﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.BidSystem.Model;

public partial class WebService_LoginService : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session.Clear();
        string username = Request.QueryString["UserName"];
        string connectkey = System.Configuration.ConfigurationManager.AppSettings["connectkey"];

        if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(connectkey))
        {
            Response.End();
            return;
        }
        else
        {
            HZ.SinglePointLogin.RedirectHelper rh = new HZ.SinglePointLogin.RedirectHelper();
            try
            {
                username = rh.DecryptUrlString(username, connectkey);
                Account account;

                var r = BLL_Factory.IBLL_Common.SinglePointLogin(username, out  account);
                if (r == 1)
                {
                    var projectlist = BLL_Factory.IBLL_Common.GetProjectList();
                    int projectid = projectlist[projectlist.Count - 1].ProjectId.Value;
                    CurrentAccount.ProjectId = projectid;

                    CurrentAccount.Account = account;

                    if (!(account.IsUsing ?? false))
                    {
                        HZ.Web.WebUtil.Alert("该用户禁用在此系统");
                        Response.End();
                    }

                    // 记录info级别日志
                    HZ.Common.log4netManager.LogInfo("单点登录系统", string.Format("登录成功:登录用户编号{0},登录IP地址{1}", account.AccountName, HZ.Fun.GetClientIP()), null);



                    if (account.AccountType.Value == 2)
                    {
                        Response.Redirect("~/Company/Default.aspx");
                    }
                    else if (account.AccountType == 1 || account.AccountType == 0)
                    {
                        Response.Redirect("~/Manage/Default.aspx");
                    }
                    else
                    {
                        HZ.Web.WebUtil.Alert("禁止该类型账户登录系统！");
                        return;
                    }
                }
                else
                {
                    HZ.Web.WebUtil.Alert("不存在该用户");
                }


            }
            catch (Exception ee)
            {

                HZ.Common.log4netManager.LogWarn("非法进入", string.Format("系统发现非法单点登录记录\r\n登录IP地址：{0}.\r\n登录串:{1}", HZ.Fun.GetClientIP(), username), ee);
                Response.End();
                return;
            }












        }
    }
}
